package model

import (
	"common-admin/entity"
)

type Admin struct {
}

func (o *Admin) FindById(id int) entity.Admin {
	db := Model().getDb()
	var admin entity.Admin
	db.First(&admin, id)
	defer Model().Close()
	return admin
}

func (o *Admin) FindOne(admin *entity.Admin) {
	db := Model().getDb()
	db.Where(admin).First(&admin)
	defer Model().Close()
}

func (o *Admin) FindByUsername(username string) entity.Admin {
	db := Model().getDb()
	var admin entity.Admin
	// 设置为true之后控制台会输出对应的SQL语句
	db.LogMode(true)
	db.Where("username = ?", username).First(&admin)
	defer Model().Close()
	return admin
}

func (o *Admin) FindAll() []entity.Admin {
	db := Model().getDb()
	admin := make([]entity.Admin, 0)
	db.First(&admin)
	defer Model().Close()
	return admin
}
